package com.sdry.web.controller.llm;

import com.sdry.mapper.cb.IDicMapper;
import com.sdry.model.llm.LlmPrepaidExpenses;
import com.sdry.model.lz.Warehouse;
import com.sdry.model.zc.ZcSysUserEntity;
import com.sdry.service.llm.LlmPrepaidExpensesService;
import com.sdry.utils.ResponseUtil;
import com.sdry.web.controller.cb.BaseController;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 *@Description: 摊销费用
 *@Author llm
 *@Date 2019-09-29 11:05:20
 *@version HAJY_1.2
*/
@Controller
@RequestMapping("/LlmPrepaidExpenses")
public class LlmPrepaidExpensesController{

	@Autowired
	private IDicMapper iDicMapper;

	@Resource 
	private LlmPrepaidExpensesService llmPrepaidExpensesService;
	
	/** 
	 * 进入页面
	 * @param model
	 * @return 页面路径
	*/
	@RequestMapping("/page")
	public String pageLlmPrepaidExpenses (Model model) {
		//仓库
		List<Warehouse> warehouseList = iDicMapper.getWarehouseList();
		model.addAttribute("warehouseList",warehouseList);
		return "/llm/LlmPrepaidExpenses";
	}
	/** 
	 * 根据主键id查询实体
	 * @param id 主键id
	 * @return 实体
	*/
	@RequestMapping("/queryById")
	@ResponseBody
	public LlmPrepaidExpenses queryById(Long id) {
		LlmPrepaidExpenses param = llmPrepaidExpensesService.queryById(id);
		return param;
	}
	/** 
	 * 条件查询所有
	 * @param param 实体条件
	 * @return 实体集合
	*/
	@RequestMapping("/queryAllByMution")
	@ResponseBody
	public List<LlmPrepaidExpenses> queryAllByMution(LlmPrepaidExpenses param) {
		List<LlmPrepaidExpenses> list = llmPrepaidExpensesService.queryAllByMution(param);
		return list;
	}
	/** 
	 * 条件分页查询
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	*/
	@RequestMapping("/list")
	public void list(LlmPrepaidExpenses param,HttpServletResponse response){
		//条件分页查询内容
		List<LlmPrepaidExpenses> list = llmPrepaidExpensesService.findPageByMution(param);
		 // 条件查询总条数
		Integer total = llmPrepaidExpensesService.selectCountByMution(param);
		//转为json数据传至页面
		JSONObject jsonObject = new JSONObject();
		JsonConfig jsonConfig = new JsonConfig();
		JSONArray jsonArray = JSONArray.fromObject(list, jsonConfig);
		jsonObject.put("code", 0);
		jsonObject.put("data", jsonArray);		
		jsonObject.put("count", total);
		try {
			ResponseUtil.write(response, jsonObject);
		}catch (Exception e) { 
			e.printStackTrace(); 
		}
	}
	/** 
	 * 插入返回id
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	*/
	@RequestMapping("/insert")
	public void insert(LlmPrepaidExpenses param, HttpServletResponse response, HttpSession session){
		ZcSysUserEntity user = (ZcSysUserEntity)session.getAttribute("user");
		if(user != null){
			param.setCreatePerson(user.getId());
		}else{
			param.setCreatePerson(0L);
		}
		param.setIsDetele(0);
		Long id = llmPrepaidExpensesService.insert(param);
		try {
			ResponseUtil.write(response, id);
		}catch (Exception e) { 
			e.printStackTrace(); 
		}
	}
	/** 
	 * 根据主键更新 返回影响行数
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	*/
	@RequestMapping("/update")
	public void update(LlmPrepaidExpenses param,HttpServletResponse response){
		Integer count = llmPrepaidExpensesService.update(param);
		try {
			ResponseUtil.write(response, count);
		}catch (Exception e) { 
			e.printStackTrace(); 
		}
	}
	/** 
	 * 根据主键拼接的字符串删除返回影响行数
	 * @param ids 主键拼接的字符串
	 * @return 影响行数
	*/
	@RequestMapping("/delete")
	public void delete(String ids,HttpServletResponse response){
		ids=ids.replace("'",""); 
		Integer count = llmPrepaidExpensesService.delete(ids);
		try {
			ResponseUtil.write(response, count);
		}catch (Exception e) { 
			e.printStackTrace(); 
		}
	}
}
